package com.probiz.estoremf.customer.web.action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.product.Product;
import com.probiz.estore.common.model.product.ProductReview;
import com.probiz.estore.core.controller.GenericCustomerFrontController;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.product.service.ProductReviewManager;
import com.probiz.estore.webapp.util.RequestContext;

public class CsProductReviewFrontController extends		GenericCustomerFrontController<ProductReview> {
	private ProductReviewManager productReviewManager;
	protected void initController() throws Exception {
		mgr = productReviewManager;
	}
	public void setProductReviewManager(ProductReviewManager productReviewManager) {
		this.productReviewManager = productReviewManager;
	}
	@Override
	protected String getEntityName(ProductReview entity) {
		return null;
	}
	@Override
	protected Map<Integer, Map<String, Object>> getMultiSaveModel(
			HttpServletRequest request) {
		return null;
	}
	@Override
	protected void preSave(HttpServletRequest request, ProductReview entity,
			BindException errors) {
		
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.core.controller.GenericCustomerFrontController#defaultAction(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * 
	 * 可发表评论的商品列表
	 */
	public ModelAndView defaultAction(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csReviewEligibleProductList");
		this.setLastSearchViewAllowed(false);
		SearchCriteria sc = createSearchCriteria(request, ProductReview.FilterHqlName.ELIGIBLE_PRODUCT_LIST);
		sc.removeParamValues();
		sc.addParamValue(RequestContext.getCurrentUserId());
		sc.addParamValue(new Date());
		List<Product> productList = this.searchByCriteria(sc);
		mv.addObject("productList", productList);
		mv.addObject("counts", productReviewManager.getCountsOfCustomer(RequestContext.getCurrentUserId()));
		return mv;
	}
	/**
	 * 我发表的评论列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView viewMyReview(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csMyReviewList");
		this.setLastSearchViewAllowed(false);
		SearchCriteria sc = createSearchCriteria(request, ProductReview.FilterHqlName.MY_REVIEW_LIST);
		sc.addParamValue(RequestContext.getCurrentUserId());
		List<ProductReview> productReviewList = this.searchByCriteria(sc);
		mv.addObject("productReviewList", productReviewList);
		mv.addObject("counts", productReviewManager.getCountsOfCustomer(RequestContext.getCurrentUserId()));
		mv.addObject("currUser", RequestContext.getCurrentUser());
		return mv;
	}
	/**
	 * 我回复的评论列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView viewMyReviewReply(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csMyReviewReplyList");
		this.setLastSearchViewAllowed(false);
		SearchCriteria sc = createSearchCriteria(request, ProductReview.FilterHqlName.MY_REVIEW_REPLY_LIST);
		sc.addParamValue(RequestContext.getCurrentUserId());
		List<ProductReview> productReviewList = this.searchByCriteria(sc);
		mv.addObject("productReviewList", productReviewList);
		mv.addObject("counts", productReviewManager.getCountsOfCustomer(RequestContext.getCurrentUserId()));
		mv.addObject("currUser", RequestContext.getCurrentUser());
		return mv;
	}
	/**
	 * 我认为有用的评论列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView viewVotedReview(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csMyVotedReviewList");
		this.setLastSearchViewAllowed(false);
		SearchCriteria sc = createSearchCriteria(request, ProductReview.FilterHqlName.MY_VOTED_REVIEW_LIST);
		sc.addParamValue(RequestContext.getCurrentUserId());
		List<ProductReview> productReviewList = this.searchByCriteria(sc);
		mv.addObject("productReviewList", productReviewList);
		mv.addObject("counts", productReviewManager.getCountsOfCustomer(RequestContext.getCurrentUserId()));
		mv.addObject("currUser", RequestContext.getCurrentUser());
		return mv;
	}
	
}
